<script type="text/javascript">
    $(document).ready(function () {

        hideContainer();
        
        $('#search').click(function (e) {
            $('#frmSearch').submit();
        })
        
        $('#friendButtonSearch').click(function(){
            $('.divContainer').hide('slow');
            $('.buttonsSelectors').show('slow');
            $(this).hide();
            $('#friendSearch').show('slow');
        })
        $('#friendButtonList').click(function(){
            $('.divContainer').hide('slow');
            $('.buttonsSelectors').show('slow');
            $(this).hide();
            $('#friendList').show('slow');
        })
        $('#requestButtonList').click(function(){
            $('.divContainer').hide('slow');
            $('.buttonsSelectors').show('slow');
            $(this).hide();
            $('#requestList').show('slow');
        })
    })
    
    function hideContainer(){
        $('.divContainer').hide();
        $('#friendList').show();
        $('#friendButtonList').hide();
    }
</script>
<div class="content-box">
    <div class="content-header">
        <h3>Administracion de Amigos</h3>
    </div>
    <div style="float: right">
        <a href="javascript:void(0)" id="friendButtonSearch" class="buttonsSelectors"><span><span>Buscar Amigos /</span></span></a>
        <a href="javascript:void(0)" id="friendButtonList" class="buttonsSelectors"><span><span>Ver Amigos /</span></span></a> 
        <a href="javascript:void(0)" id="requestButtonList" class="buttonsSelectors"><span><span>Solicitudes de Amistad (<?php echo count($this->requesters) ?>)</span></span></a> 
    </div>

    <div id="requestList" class="divContainer">
        <h2>Solicitudes de Amistad (<?php echo count($this->requesters) ?>)</h2> 
        <?php if (count($this->requesters) != 0) : ?>
            <table style="width: 100%">
                <thead>
                <th>Nombre</th>
                <th>Apellido</th>
                <th>e-mail</th>
                <th>Amistad</th>
                <th></th>
                </thead>                

                <?php foreach ($this->requesters as $requester): ?>

                    <?php $requesterData = User::findOneById($requester->id_user) ?>
                    <tr>
                        <td><?php echo $requesterData->profile->name; ?></td>
                        <td><?php echo $requesterData->profile->surname; ?></td>
                        <td><?php echo $requesterData->email; ?></td>
                        <?php if (Friendship::checkFriendStatus($requesterData->id) == Friendship::ARE_FRIEND): ?>
                            <td>Ya eres amigo!!</a></td>
                        <?php endif; ?>

                        <?php if (Friendship::checkFriendStatus($requesterData->id) == Friendship::INVITES_HIM): ?>
                            <td>Solicitud Enviada</a></td>
                        <?php endif; ?>

                        <?php if (Friendship::checkFriendStatus($requesterData->id) == Friendship::INVITE_ME): ?>
                            <td><a class="addFriend" href="/friendship/acceptfriend/id/<?php echo $requesterData->id; ?>">Aceptar Solicitud</a></td>
                        <?php endif; ?>

                        <td><a class="deleteLink" href="/friendship/deletefriend/id/<?php echo $requesterData->id; ?>">Eliminar</a></td>
                    </tr>

                <?php endforeach; ?>
            </table>
        <?php else: ?>
            <h3>No hay solicitudes pendientes</h3>
        <?php endif; ?>

    </div>

    <div id="friendList" class="divContainer">
        <h2>Amigos</h2>
        <?php if (count($this->friends) != 0) : ?>
            <table style="width: 100%">
                <thead>
                <th>Nombre</th>
                <th>Apellido</th>
                <th>e-mail</th>
                <th>Amistad</th>
                <th></th>
                </thead>                

                <?php foreach ($this->friends as $friend): ?>

                    <?php $friendData = User::findOneById($friend->id_friend) ?>
                    <tr>
                        <td><?php echo $friendData->profile->name; ?></td>
                        <td><?php echo $friendData->profile->surname; ?></td>
                        <td><?php echo $friendData->email; ?></td>
                        <?php if (Friendship::checkFriendStatus($friendData->id) == Friendship::ARE_FRIEND): ?>
                            <td>Ya eres amigo!! - <a href="/wall/index/idUser/<?php echo $friendData->id ?>">Ver muro</a></td>
                        <?php endif; ?>

                        <?php if (Friendship::checkFriendStatus($friendData->id) == Friendship::INVITES_HIM): ?>
                            <td>Solicitud Enviada</a></td>
                        <?php endif; ?>

                        <?php if (Friendship::checkFriendStatus($friendData->id) == Friendship::INVITE_ME): ?>
                            <td><a class="addFriend" href="/friendship/acceptfriend/id/<?php echo $friendData->id; ?>">Aceptar Solicitud</a></td>
                        <?php endif; ?>

                        <td><a class="deleteLink" href="/friendship/deletefriend/id/<?php echo $friendData->id; ?>">Eliminar</a></td>
                    </tr>

                <?php endforeach; ?>
            </table>
        <?php else: ?>
            <h3>No hay Amigos</h3>
        <?php endif; ?>

    </div>

    <div id="friendSearch" class="divContainer">
        <h2>Buscar amigos :)</h2>
        <form id="frmSearch" action="/friend/search" method="post">
            <div>
                <label>Nombre</label>
                <input type="text" name="name" size="30" class="required"/>
            </div>
            <div>
                <label>Apellido</label>
                <input type="text" name="surname" size="30" class="required"/>
            </div>
            <div>
                <label>e-mail</label>
                <input type="text" name="email" size="30" class="required"/>
            </div>

            <p class="link">
                <a href="javascript:void(0)" id="search"><span><span>Buscar</span></span></a>
            </p>
        </form>

    </div>

</div>

